package com.bed.lovewithpatientbed.service.impl;

import com.bed.lovewithpatientbed.dao.PermissionDao;
import com.bed.lovewithpatientbed.dao.RolePermissionDao;
import com.bed.lovewithpatientbed.pojo.Permission;
import com.bed.lovewithpatientbed.pojo.PermissionExample;
import com.bed.lovewithpatientbed.pojo.RolePermission;
import com.bed.lovewithpatientbed.pojo.RolePermissionExample;
import com.bed.lovewithpatientbed.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xuxiaoding
 * @version 1.0.0
 * @ClassName PermissionServiceImpl.java
 * @Description TODO
 */
@Service
public class PermissionServiceImpl implements IPermissionService {

    private PermissionDao permissionDao;

    private RolePermissionDao rolePermissionDao;

    @Autowired
    public void setPermissionDao(PermissionDao permissionDao) {
        this.permissionDao = permissionDao;
    }

    @Autowired
    public void setRolePermissionDao(RolePermissionDao rolePermissionDao) {
        this.rolePermissionDao = rolePermissionDao;
    }

    @Override
    public List<RolePermission> getRolePermissionByRoleId(Integer roleId) {
        if (roleId == null || roleId < 1) {
            return null;
        }

        RolePermissionExample rolePermissionExample = new RolePermissionExample();
        rolePermissionExample.createCriteria().andRoleIdEqualTo(roleId);
        return rolePermissionDao.selectByExample(rolePermissionExample);
    }

    @Override
    public List<Permission> getPermissionByPermissionId(List<Integer> permissions) {
        if (permissions == null || permissions.size() < 1) {
            return null;
        }

        PermissionExample permissionExample = new PermissionExample();
        permissionExample.createCriteria().andPermissionIdIn(permissions);

        return permissionDao.selectByExample(permissionExample);
    }

    @Override
    public Permission getPermissionByPermissionId(Integer permissionId) {
        if (permissionId == null || permissionId < 1) {
            return null;
        }
        return permissionDao.selectByPrimaryKey(permissionId);
    }
}
